home *** CD-ROM | disk | FTP | other *** search
/ Aminet 28 / Aminet 28 (1998)(GTI - Schatztruhe)[!][Dec 1998].iso / Aminet / util / libs / graphics3d.lha / src / library / graphics3Dsu.c < prev   
Encoding:
C/C++ Source or Header  |  1998-10-17  |  8.2 KB  |  306 lines

  1. /*
  2. **      $VER: StartUp.c 37.16 (23.8.97)
  3. **
  4. **      Library startup-code and function table definition
  5. **
  6. **      (C) Copyright 1996-97 Andreas R. Kleinert
  7. **      All Rights Reserved.
  8. */
  9.  
  10. #include <exec/types.h>
  11. #include <exec/memory.h>
  12. #include <exec/libraries.h>
  13. #include <exec/execbase.h>
  14. #include <exec/resident.h>
  15. #include <exec/initializers.h>
  16.  
  17. #include <proto/exec.h>    /* all other compilers */
  18.  
  19. #include "graphics3Dc.h"
  20.  
  21. #include "graphics3Dbase.h"
  22. #include "graphics3D2D.h"
  23. #include "graphics3Df.h"
  24.  
  25. extern ULONG L_OpenLibs(void);
  26. extern void  L_CloseLibs(void);
  27.  
  28. struct Graphics3DBase *InitLib( REG(a6) struct ExecBase *sysbase,
  29.                     REG(a0) struct SegList *seglist,
  30.                     REG(d0) struct Graphics3DBase *exb );
  31.  
  32. struct Graphics3DBase *OpenLib( REG(a6) struct Graphics3DBase *ExampleBase);
  33.  
  34. APTR CloseLib( REG(a6) struct Graphics3DBase *Graphics3DBase );
  35.  
  36. APTR ExpungeLib( REG(a6) struct Graphics3DBase *exb);
  37.  
  38. ULONG ExtFuncLib(void);
  39.  
  40.  
  41. /* -------------------------------------------------------------------------
  42.  ! LibStart:
  43.  !
  44.  ! If someone tries to start a library as an executable, it must return 
  45.  ! (LONG) -1 as result. That's what we are doing here.
  46.  ------------------------------------------------------------------------ */
  47.  
  48. LONG LibStart(void)
  49. {
  50.  return(-1);
  51. }
  52.  
  53.  
  54. /* -------------------------------------------------------------------------
  55.  ! Function and Data Tables:
  56.  !
  57.  ! The function and data tables have been placed here for traditional 
  58.  ! reasons.
  59.  ! Placing the RomTag structure before (-> LibInit.c) would also be a good 
  60.  ! idea, but it depends on whether you would like to keep the "version" 
  61.  ! stuff separately.
  62.  ------------------------------------------------------------------------ */
  63.  
  64. extern APTR FuncTab [];
  65. extern struct MyDataInit DataTab; 
  66. /* instead you may place ROMTag + Datatab directly, here */
  67. /* (see LibInit.c). This may fix "Installer" version     */
  68. /* checking problems, too.                               */
  69.  
  70. struct InitTable                       /* do not change */
  71. {
  72.  ULONG              LibBaseSize;
  73.  APTR              *FunctionTable;
  74.  struct MyDataInit *DataTable;
  75.  APTR               InitLibTable;
  76. } InitTab =
  77. {
  78.  sizeof(struct Graphics3DBase),
  79.  &FuncTab[0],
  80.  &DataTab,
  81.  InitLib
  82. };
  83.  
  84. APTR FuncTab [] =
  85. {
  86.  OpenLib,
  87.  CloseLib,
  88.  ExpungeLib,
  89.  ExtFuncLib,
  90.  
  91. /* add your own functions here */
  92.  
  93. /* pubbliche */
  94. /* for compatibility , don't change never the order of this functions */
  95. /* add the new one after the last **/
  96.  GD_switch_rp,
  97.  GD_clipbox,
  98.  GD_cls_b,
  99.  GD_over,
  100.  GD_display3d,
  101.  GD_close_display3d,
  102.  GD_changeviewmode,
  103.  GD_changeviewmodeobj,
  104.  GD_touchpalette,
  105.  GD_moveforward,
  106.  GD_viewangle,
  107.  GD_frustum,
  108.  GD_createlightsource,
  109.  GD_ambientlight,
  110.  GD_positioncamera,
  111.  GD_aspectratio,
  112.  GD_clipmode,
  113.  GD_newobj,
  114.  GD_deleteobject,
  115.  GD_addobjvertex,
  116.  GD_addobjpoly,
  117.  GD_cattpoly,
  118.  GD_setobj,
  119.  GD_getobj,
  120.  GD_translateobject,
  121.  GD_positionobject,
  122.  GD_scaleobject,
  123.  GD_rotateobject,
  124.  GD_pickobj,
  125.  GD_rgb4,
  126.  GD_paintframe,
  127.  GD_newview,
  128.  GD_recalcobj,
  129.  GD_cascene,
  130.  GD_int2fix,
  131.  GD_fix2int,
  132.  GD_sfl2fix,
  133.  GD_fix2sfl,
  134.  GD_dfl2fix,
  135.  GD_fix2dfl,
  136.  
  137. /* add the new one from here **/
  138.  
  139. /* private */
  140.  
  141. /* tappo */
  142.  (APTR) ((LONG)-1)
  143. };
  144.  
  145.  
  146. extern struct Graphics3DBase *Graphics3DBase;
  147.  
  148. /* -------------------------------------------------------------------------
  149.  ! InitLib:
  150.  !
  151.  ! This one is single-threaded by the Ramlib process. Theoretically you can 
  152.  ! do, what you like here, since you have full exclusive control over all 
  153.  ! the library code and data.
  154.  ! But due to some bugs in Ramlib V37-40, you can easily cause a deadlock 
  155.  ! when opening certain libraries here (which open other libraries, that 
  156.  ! open other libraries, that...)
  157.  ------------------------------------------------------------------------ */
  158.  
  159. struct Graphics3DBase *InitLib( REG(a6) struct ExecBase *sysbase,
  160.                     REG(a0) struct SegList *seglist,
  161.                     REG(d0) struct Graphics3DBase *exb)
  162. {
  163.  Graphics3DBase = exb;
  164.  
  165.  Graphics3DBase->exb_SysBase = sysbase;
  166.  Graphics3DBase->exb_SegList = seglist;
  167.  
  168.  if(L_OpenLibs()) return(Graphics3DBase);
  169.  
  170.  L_CloseLibs();
  171.  
  172.   {
  173.    ULONG negsize, possize, fullsize;
  174.    UBYTE *negptr = (UBYTE *) Graphics3DBase;
  175.  
  176.    negsize  = Graphics3DBase->exb_LibNode.lib_NegSize;
  177.    possize  = Graphics3DBase->exb_LibNode.lib_PosSize;
  178.    fullsize = negsize + possize;
  179.    negptr  -= negsize;
  180.  
  181.    FreeMem(negptr, fullsize);
  182.  
  183.   }
  184.  
  185.  return(NULL);
  186. }
  187.  
  188. /* -------------------------------------------------------------------------
  189.  ! OpenLib:
  190.  !
  191.  ! This one is enclosed within a Forbid/Permit pair by Exec V37-40. Since a 
  192.  ! Wait() call would break this Forbid/Permit(), you are not allowed to 
  193.  ! start any operations that may cause a Wait() during their processing. 
  194.  ! It's possible, that future OS versions won't turn the multi-tasking off, 
  195.  ! but instead use semaphore protection for this function.
  196.  !
  197.  ! Currently you only can bypass this restriction by supplying your own 
  198.  ! semaphore mechanism.
  199.  ------------------------------------------------------------------------ */
  200.  
  201. struct Graphics3DBase *OpenLib( REG(a6) struct Graphics3DBase *ExampleBase)
  202. {
  203.  
  204.  Graphics3DBase->exb_LibNode.lib_OpenCnt++;
  205.  
  206.  Graphics3DBase->exb_LibNode.lib_Flags &= ~LIBF_DELEXP;
  207.  
  208.  return(Graphics3DBase);
  209. }
  210.  
  211. /* -------------------------------------------------------------------------
  212.  ! CloseLib:
  213.  !
  214.  ! This one is enclosed within a Forbid/Permit pair by Exec V37-40. Since a 
  215.  ! Wait() call would break this Forbid/Permit(), you are not allowed to 
  216.  ! start any operations that may cause a Wait() during their processing. 
  217.  ! It's possible, that future OS versions won't turn the multi-tasking off, 
  218.  ! but instead use semaphore protection for this function.
  219.  !
  220.  ! Currently you only can bypass this restriction by supplying your own 
  221.  ! semaphore mechanism.
  222.  ------------------------------------------------------------------------ */
  223.  
  224. APTR CloseLib( REG(a6) struct Graphics3DBase *Graphics3DBase )
  225. {
  226.  Graphics3DBase->exb_LibNode.lib_OpenCnt--;
  227.  
  228.  if(!Graphics3DBase->exb_LibNode.lib_OpenCnt)
  229.   {
  230.    if(Graphics3DBase->exb_LibNode.lib_Flags & LIBF_DELEXP)
  231.     {
  232.      return( ExpungeLib(Graphics3DBase) );
  233.     }
  234.   }
  235.  
  236.  return(NULL);
  237. }
  238.  
  239. /* -------------------------------------------------------------------------
  240.  ! ExpungeLib:
  241.  !
  242.  ! This one is enclosed within a Forbid/Permit pair by Exec V37-40. Since a 
  243.  ! Wait() call would break this Forbid/Permit(), you are not allowed to 
  244.  ! start any operations that may cause a Wait() during their processing. 
  245.  ! It's possible, that future OS versions won't turn the multi-tasking off, 
  246.  ! but instead use semaphore protection for this function.
  247.  !
  248.  ! Currently you only could bypass this restriction by supplying your own 
  249.  ! semaphore mechanism - but since expunging can't be done twice, one 
  250.  ! should avoid it here.
  251.  ------------------------------------------------------------------------ */
  252.  
  253. APTR ExpungeLib( REG(a6) struct Graphics3DBase *exb )
  254. {
  255.  struct Graphics3DBase *Graphics3DBase = exb;
  256.  struct SegList *seglist;
  257.  
  258.  if(!Graphics3DBase->exb_LibNode.lib_OpenCnt)
  259.   {
  260.    ULONG negsize, possize, fullsize;
  261.    UBYTE *negptr = (UBYTE *) Graphics3DBase;
  262.  
  263.    seglist = Graphics3DBase->exb_SegList;
  264.  
  265.    Remove((struct Node *)Graphics3DBase);
  266.  
  267.    L_CloseLibs();
  268.  
  269.    negsize  = Graphics3DBase->exb_LibNode.lib_NegSize;
  270.    possize  = Graphics3DBase->exb_LibNode.lib_PosSize;
  271.    fullsize = negsize + possize;
  272.    negptr  -= negsize;
  273.  
  274.    FreeMem(negptr, fullsize);
  275.  
  276.    return(seglist);
  277.   }
  278.  
  279.  Graphics3DBase->exb_LibNode.lib_Flags |= LIBF_DELEXP;
  280.  
  281.  return(NULL);
  282. }
  283.  
  284. /* -------------------------------------------------------------------------
  285.  ! ExtFunct:
  286.  !
  287.  ! This one is enclosed within a Forbid/Permit pair by Exec V37-40. Since a 
  288.  ! Wait() call would break this Forbid/Permit(), you are not allowed to 
  289.  ! start any operations that may cause a Wait() during their processing. 
  290.  ! It's possible, that future OS versions won't turn the multi-tasking off, 
  291.  ! but instead use semaphore protection for this function.
  292.  !
  293.  ! Currently you only can bypass this restriction by supplying your own 
  294.  ! semaphore mechanism - but since this function currently is unused, you 
  295.  ! should not touch it, either.
  296.  ------------------------------------------------------------------------ */
  297.  
  298. ULONG ExtFuncLib(void)
  299. {
  300.  return(NULL);
  301. }
  302.  
  303. struct Graphics3DBase *Graphics3DBase = NULL;
  304.  
  305.  
  306.